// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    //本地储存
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // console.log(res.code);
        // console.log(res.code);
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        wx.request({

          url: this.globalData.url + '/wxapi/login/wxLogin?code' + res.code,
          data:{
            code:res.code
          },
            header:{
              'content-type':'application/x-wwww-from-urlencoded'
            },
            success: res =>{
              if(res.data.code === 200){
                if(res.data.data.openid){
                  this.globalData.openid = res.data.data.openid;
                  this.globalData.session_key = res.data.data.session_key;
                  console.log(this.globalData.openid)
                console.log(this.globalData.session_key)
                  wx.setStorageSync('openid', res.data.data.openid)
                }
              }
            }
        })
      }
    })
  },
  globalData: {
    userInfo: null,
    url:"http://localhost:8099",
    openid:"",
    session_key:'',
    token:''
  }
})
